package krow.dev.addetector.util;

import android.content.Context;
import android.support.v7.appcompat.R;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.WindowManager;

public class DisplayUtil {

	public static int getStatusBarHeight(Context context) {
		int height = 0;
		int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
		if (resourceId > 0) {
			height = context.getResources().getDimensionPixelSize(resourceId);
		}
		return height;
	}
	
	public static int getNavigationBarHeight(Context context) {
		int height = 0;
		int resourceId = context.getResources().getIdentifier("navigation_bar_height", "dimen", "android");
		if (resourceId > 0) {
			height = context.getResources().getDimensionPixelSize(resourceId);
		}
		return height;
	}
	
	public static int getActionBarHeight(Context context) {
		int height = 0;
		try {
			height = context.getResources().getDimensionPixelSize(R.dimen.abc_action_bar_default_height);
		} catch (Exception e) {

		}
		return height;
	}
	
	public static int getPixelToDimension(Context context, int pixel) {

		DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();

		int dip = (int) (pixel / (displayMetrics.densityDpi / 160));

		return dip;
	}

	public static int getDimensionToPixel(Context context, float dip) {

		DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();

		int pixel = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dip, displayMetrics);

		return pixel;
	}

	public static int getDimensionToId(Context context, int id) {
		int pixel = 0;
		try {
			pixel = (int) context.getResources().getDimension(id);
		} catch (Exception e) {

		}
		return pixel;
	}

	public static int getDisplayWidth(Context context) {
		DisplayMetrics displayMetrics = new DisplayMetrics();

		WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
		windowManager.getDefaultDisplay().getMetrics(displayMetrics);

		return displayMetrics.widthPixels;
	}

	public static int getDisplayHeight(Context context) {
		DisplayMetrics displayMetrics = new DisplayMetrics();

		WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
		windowManager.getDefaultDisplay().getMetrics(displayMetrics);

		return displayMetrics.heightPixels;
	}
}
